package com.nit.bike.mapper.bike;

import com.nit.bike.dto.bike.RideDTO;
import com.nit.bike.entity.bike.RideEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface RideMapper {
    int deleteByPrimaryKey(Long rideId);

    int insert(RideEntity record);

    int insertSelective(RideEntity record);

    RideEntity selectByPrimaryKey(Long rideId);

    int updateByPrimaryKeySelective(RideEntity record);

    int updateByPrimaryKey(RideEntity record);

    /**
     * 查询人员当前骑行记录
     */
    @Select("SELECT * " +
            "FROM basic_ride r " +
            "JOIN basic_user u ON r.user_id = u.user_id AND u.ride_id = r.ride_id " +
            "WHERE u.user_id = #{userId} " +
            "LIMIT 1")
    RideDTO queryByUserId(@Param("userId") Long userId) throws Exception;

    /**
     * 查询从用户表关联的骑行记录
     */
    @Select("SELECT * " +
            "FROM basic_ride r " +
            "RIGHT JOIN basic_user u ON r.user_id = u.user_id AND u.ride_id = r.ride_id " +
            "WHERE u.ride_id = #{rideId} " +
            "LIMIT 1")
    RideDTO queryByIdFromUser(@Param("rideId") Long rideId) throws Exception;

    /**
     * 插入数据后立刻查询
     */
    @Select("SELECT LAST_INSERT_ID()")
    Long queryRideId() throws Exception;
}
